package com.github.niefy.modules.wx.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.niefy.config.properties.ApplicationProperties;
import com.github.niefy.modules.wx.bean.CloudWxMpServiceImpl;

import me.chanjar.weixin.mp.api.WxMpService;

@EnableConfigurationProperties({ ApplicationProperties.class })
@Configuration
public class WxMpServiceConfiguration {

	@Autowired
	private ApplicationProperties applicationProperties;
	
	@Bean
	public WxMpService wxMpService() {
		// WxMpService wxMpService = new WxMpServiceImpl();
		CloudWxMpServiceImpl wxMpService = new CloudWxMpServiceImpl();
		wxMpService.setAccessTokenUrl(this.applicationProperties.getHost().concat(this.applicationProperties.getAccessTokenPath()));
		wxMpService.setMaxRetryTimes(3);
		return wxMpService;
	}
}
